package com.example.ppp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ppp.entity.Address;
import com.example.ppp.entity.Count;
import com.example.ppp.entity.User;
import com.example.ppp.mapper.CountMapper;
import com.example.ppp.mapper.UserMapper;
import com.example.ppp.service.AddressService;
import com.example.ppp.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author admin
* @description 针对表【address】的数据库操作Service实现
* @createDate 2023-05-18 13:27:58
*/
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address>
    implements AddressService{

    @Autowired
    private CountMapper countMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private AddressMapper addressMapper;

    @Override
    public void insertAddress() {
        long start = System.currentTimeMillis();
        List<Address> addressList = new ArrayList<>();
        List<User> users = userMapper.selectList(null);
        int i = 0;
        if (users.size() > 0) {
            for (User user : users) {
                Address address = new Address();
                address.setUser_id(user.getId());
                address.setCity("南京");
                address.setAddress("南京"+i+"区");
                i+=1;
                addressList.add(address);
            }
            addressMapper.insertBatchSomeColumn(addressList);
            long end = System.currentTimeMillis();
            System.out.println("一万条数据总耗时：" + (end - start) + "ms");
        }

    }

}




